package com.cn.study.fourth.stage.zuoye1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ListTest {
    public static List<Student> allStudent = new ArrayList<>();

    //初始化数据用
    static {
        allStudent.add(new Student("001", "1号", "男", 20, 161));
        allStudent.add(new Student("002", "2号", "女", 21, 171));
        allStudent.add(new Student("003", "3号", "男", 22, 181));
    }

    //判断密码
    public boolean login(String password) {
        if (password.equals("123456")) {
            return true;
        } else {
            return false;
        }
    }

    //查询所有
    public void findAll() {
        for (Student s : allStudent) {
            System.out.println(s);
        }
    }

    //增加学生
    public boolean addStudent(Student student) {
        return allStudent.add(student);
    }

    //删除学生
    public boolean deleteStudent(String number) {
        for (int i = 0; i < allStudent.size(); i++) {
            if (allStudent.get(i).getNumber().equals(number)) {
                return allStudent.remove(allStudent.get(i));
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //判断密码
        System.out.println("请输入密码");
        ListTest StudentManage = new ListTest();
        if (StudentManage.login(scanner.nextLine())) {
            System.out.println("------打印所有--------");
            StudentManage.findAll();
            System.out.println("----------------------");
            //创建两个学生对象
            Student s1 = new Student("004", "4号", "男", 23, 191);
            //加入list集合
            if (StudentManage.addStudent(s1)) {
                System.out.println("添加成功");
            } else {
                System.out.println("添加失败");
            }
            System.out.println("------打印所有--------");
            StudentManage.findAll();
            System.out.println("----------------------");
            //删除
            System.out.println("请输入删除学号");
            if (StudentManage.deleteStudent(scanner.nextLine())) {
                System.out.println("删除成功");
            } else {
                System.out.println("删除失败");
            }
            System.out.println("------打印所有--------");
            StudentManage.findAll();
            System.out.println("----------------------");
        }
    }
}
